package com.dream.contacts;


import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
import android.util.Log;

public class SmartDialQuery {
	
	   private static final String GROUP_SELECT = 
	    		"raw_contact_id IN (SELECT raw_contact_id FROM data WHERE " +  GroupMembership.GROUP_ROW_ID + "="
	                    + "(SELECT " + "groups" + "." + Groups._ID
	                    + " FROM " + "groups"
	                    + " WHERE " + Groups.DELETED + "=0 AND " 
	                    	+ Groups.TITLE + "= 'Schoolmate'))" ;
	
	public static String getResult(Context context,String filter){
		
		Uri uri = Uri.withAppendedPath(ContactsContract.AUTHORITY_URI ,"contacts_all/filter");
//		Uri uri = Uri.withAppendedPath(ContactsContract.AUTHORITY_URI ,"contacts_all/Schoolmate/filter");
		Uri filterUri = Uri.withAppendedPath(uri,Uri.encode(filter));
		Cursor cursor = context.getContentResolver().query(filterUri, null, null, null, "sort_key");
		
		StringBuilder sb = new StringBuilder();
		if(cursor != null && cursor.getCount() > 0){
			int columnCount = cursor.getColumnCount();
			while(cursor.moveToNext()){
				for(int i = 0 ; i < columnCount;i++){
					sb.append(cursor.getColumnName(i)+" ~~~ " + cursor.getString(i) + "  ");
				}
				Log.d("SmartDialQuery", sb.toString());
				
			}
		}
		return sb.toString();
	}
}
